Thread: [Help] C + Gtk+

  1. #1
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193

    Exclamation [Help] C + Gtk+

    I'm getting a segmentation failure (that's the traduction from spanish tu english)
    Code:
    void callback_main_button_build( GtkObject *object ) {
    GtkWidget *frame_build;
    GtkWidget *table;
    GtkWidget *button_build;
    GtkWidget *text_id;
    GtkWidget *text_passwd;
    GtkWidget *text_name;
    GtkWidget *text_place;
    GtkWidget *text_keyname;
    GtkWidget *label_id;
    GtkWidget *label_passwd;
    GtkWidget *label_name;
    GtkWidget *label_place;
    GtkWidget *label_keyname;
    
    table = gtk_table_new(6, 2, FALSE);
    label_id = gtk_label_new("ID:");
    label_passwd = gtk_label_new("Passwd:");
    label_name = gtk_label_new("Name:");
    label_place = gtk_label_new("Place:");
    label_keyname = gtk_label_new("Keyname:");
    text_id = gtk_entry_new();
    text_passwd = gtk_entry_new();
    text_name = gtk_entry_new();
    text_place = gtk_entry_new();
    text_keyname = gtk_entry_new();
    button_build = gtk_button_new_with_label ("Build");
    frame_build = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(frame_build), 250, 200);
    gtk_window_set_title(GTK_WINDOW(frame_build), "Build Card");
    gtk_container_add(GTK_CONTAINER(frame_build), table);
    gtk_table_attach_defaults(GTK_TABLE(table), label_id, 0, 1, 0, 1);
    gtk_table_attach_defaults(GTK_TABLE(table), text_id, 1, 2, 0, 1);
    gtk_table_attach_defaults(GTK_TABLE(table), label_place, 0, 1, 1, 2);
    gtk_table_attach_defaults(GTK_TABLE(table), text_place, 1, 2, 1, 2);
    gtk_table_attach_defaults(GTK_TABLE(table), label_name, 0, 1, 2, 3);
    gtk_table_attach_defaults(GTK_TABLE(table), text_name, 1, 2, 2, 3);
    gtk_table_attach_defaults(GTK_TABLE(table), label_passwd, 0, 1, 3, 4);
    gtk_table_attach_defaults(GTK_TABLE(table), text_passwd, 1, 2, 3, 4);
    gtk_table_attach_defaults(GTK_TABLE(table), label_keyname, 0, 1, 4, 5);
    gtk_table_attach_defaults(GTK_TABLE(table), text_keyname, 1, 2, 4, 5);
    gtk_table_attach_defaults(GTK_TABLE(table), button_build, 0, 1, 5, 6);
    gtk_widget_show_all(frame_build);
    }
    I'm calling this form with this code

    Code:
    gtk_signal_connect(GTK_OBJECT(menu_main_file_build), "activate", GTK_SIGNAL_FUNC(callback_main_button_build), NULL);
    It's really strange cause i did it with another form and it worked but, the last two aren't working..
    Thanks..

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Wow...do you have ANY idea why?

    I would run it thru a debugger and find out exactly where the segfault occurs.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    I had a brief look over this and I cant see anything wrong with it, but then I dont have all that much experience wutrh gtk+. gtk_signal_connect is deprecated tho so you might want to look at using g_signal_connect instead. Also, do try runnning it with a debugger, or at least be descriptive about your problem. I have no idea what you mean by "the last two aren't working" Last two what

  4. #4
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    The last two windows I've created don't work, only one works, thats why I said that, and g_signal_connect is not interpreted by my compiler, so I used gtk_signal_connect that was on another manual..

  5. #5
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    I was working from a tutorial that used gtk_signal_connect, a lot of the gtk stuff on the net is outdated. You might be best off downloading the reference manual: http://library.gnome.org/devel/gtk/

    If you strip out all the content so you're basically left with an empty window will that work? Trial and error can help find where your problem is. Also, have you tried running it in debug (-g)?

  6. #6
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    I didn't knew, but i was compiling with the old gtk+ library, now i have compiled it with gtk+-2.0 and I'm getting this error..

    (pbclient:13596): Gtk-CRITICAL **: gtk_window_set_default_size: assertion `GTK_IS_WINDOW (window)' failed

    (pbclient:13596): Gtk-CRITICAL **: gtk_window_set_title: assertion `GTK_IS_WINDOW (window)' failed

    (pbclient:13596): Gtk-CRITICAL **: gtk_container_add: assertion `GTK_IS_CONTAINER (container)' failed

    (pbclient:13596): Gtk-CRITICAL **: gtk_widget_show_all: assertion `GTK_IS_WIDGET (widget)' failed

    It's like failing on creating this windows, but in another one I have, there are no errors..

  7. #7
    Registered User
    Join Date
    Jul 2004
    Posts
    222
    I don't know much about GTK. Other than running the code through a debugger, a gtk-related forum may help you more (http://www.gtkforums.com/ as an example). That's just my two cents.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MinGW32 and gtk setup in Windows
    By Joelito in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 02-05-2009, 11:39 AM
  2. Replies: 1
    Last Post: 09-22-2008, 04:49 AM
  3. GTK troubles...again...
    By cornholio in forum Linux Programming
    Replies: 4
    Last Post: 01-16-2006, 01:37 AM
  4. Replies: 1
    Last Post: 10-24-2005, 06:35 AM
  5. Gtk
    By curlious in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 01-01-2005, 12:05 PM